package app.backend.service.impl;

import app.backend.entity.BizCarousel;
import app.backend.entity.DevFile;
import app.backend.mapper.BizCarouselMapper;
import app.backend.service.BizCarouselService;
import app.backend.service.BizFileService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 轮播图信息表 服务实现类
 *
 * @author 程开磊
 * @date  2025/09/06 14:31
 */
@Service
@Slf4j
public class BizCarouselServiceImpl extends ServiceImpl<BizCarouselMapper, BizCarousel> implements BizCarouselService {

    @Resource
    private BizFileService bizFileService;

    /**
     * 查询开启状态的轮播图，按排序字段升序排序
     *
     * @return 轮播图列表
     */
    @Override
    public List<BizCarousel> getEnabledCarousels() {
        QueryWrapper<BizCarousel> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BizCarousel::getDeleteFlag, "NOT_DELETE")
                  .eq(BizCarousel::getIsEnable, "1")
                  .orderByAsc(BizCarousel::getSortOrder);
        List<BizCarousel> list = list(queryWrapper);
        for (BizCarousel carousel : list) {
            DevFile devFile = bizFileService.getById(carousel.getImageId());
            carousel.setImageUrl(devFile.getDownloadPath());
        }
        return list;
    }
}
